package com.dnjn.happiness.survey.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.survey.domain.Answer;
import com.dnjn.happiness.survey.domain.SurveyRecord;
import com.dnjn.happiness.survey.domain.vo.AnswerVO;
import com.dnjn.happiness.survey.domain.vo.SurveyUserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Amber
 * @since 2023-10-04
 */
public interface AnswerMapper extends BaseMapper<Answer> {
    /**
     * 小程序-我的问卷-这个应该是答案详情--
     */
    Page<Answer> selectAnswerList(@Param("dto") SurveyRecord domain, Page page);

    @Select("SELECT a.answer,LOCATE(#{option},a.answer) AS num FROM svy_answer a WHERE a.question_id = #{questionId} HAVING num > 0")
    List<Answer> selectAnswerCount(@Param("option") String option, @Param("questionId") Long questionId);

    @Select("SELECT a.answer,b.score_option_a scoreOptionA,b.score_option_b scoreOptionB,b.score_option_c scoreOptionC,b.score_option_d scoreOptionD,b.score_option_e scoreOptionE,b.score_option_f scoreOptionF,b.score_option_g scoreOptionG FROM svy_answer a JOIN svy_question b USING(question_id) WHERE a.question_id = #{questionId}")
    List<Answer> selectAnswerListAndScore(Long questionId);

    List<SurveyUserVO> screeningSubmit(@Param("dto") AnswerVO answerVO);


}
